package com.cater.talents.service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.DictionarydataDao;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.BaseService;
import com.cater.talents.dao.CellPhoneDao;
import com.cater.talents.dao.ResumeDao;
import com.cater.talents.entity.Resume;

/**
 * @author yong
 * @Date 2018年3月22日-下午9:48:16
 * @简历管理实现层
 */
@Service
public class ResumeServiceImpl implements BaseService<Resume, CommonQuery, String> {
	@Autowired
	ResumeDao dao;
	@Autowired
	CellPhoneDao cellPhoneDao;
	@Autowired
	DictionarydataDao dictDao;

	@Override
	public PageResult<Resume> findPageResult(CommonQuery query) {
		PageResult<Resume> result = new PageResult<Resume>();
		Dictionarydata dictType = null;
		Dictionarydata dictStatus = null;
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<Resume> list = dao.findList(query, first, max);
		for (Resume t : list) {
			String type = t.getType();
			if (StringUtils.isNotEmpty(type)) {
				dictType = dictDao.getByTypeValue(t.getType(), "resume_type");
				t.setDictType(dictType.getValueName());
			}
			String status = t.getStatus();
			if (StringUtils.isNotEmpty(status)) {
				dictStatus = dictDao.getByTypeValue(status, "resume_status");
				t.setDictStatus(dictStatus.getValueName());
			} else {
				t.setDictStatus("无");
			}
		}
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<Resume> getAll() {
		return dao.getAll();
	}

	@Override
	public List<Resume> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(Resume t) {
		return 0;
	}

	@Override
	public String saves(Resume t) {
		if(StringUtils.isEmpty(t.getId())) {
			t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		}
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(Resume t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public Resume getById(String id) {
		return dao.getById(id);
	}

	public List<Resume> getByName(CommonQuery query) {
		return dao.getByName(query);
	}

	public List<Map<String, String>> getAnalysisCreate(CommonQuery query) {
		return dao.getAnalysisCreate(query);
	}
	
	public List<Map<String, String>> getAnalysisUpdate(CommonQuery query) {
		return dao.getAnalysisUpdate(query);
	}
	
	public List<Map<String, String>> getResumeForIndex(CommonQuery query){
		return dao.getResumeForIndex(query);
	}

}
